package gui;

import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;


/**
 * The listener that's notified when a lists selection value
 * changes.
 *
 * @see javax.swing.ListSelectionModel
 *
 * @version 1.12 12/19/03
 * @author Hans Muller
 */

public class MyListListener implements ListSelectionListener {

    JList list;
    JButton removeUserButton;
    JButton editUserButton;

    public MyListListener(JList l, JButton b1, JButton b2){
        list = l;

        removeUserButton = b1;
        editUserButton = b2;


    }

    public void valueChanged(ListSelectionEvent e) {
        if (e.getValueIsAdjusting() == false) {

            if (list.getSelectedIndex() == -1) {
            //No Selection: enable add user

                removeUserButton.setEnabled(false);
                editUserButton.setEnabled(false);

            } else if(list.getSelectedIndex() == 0){
            //Selected new user: disable remove & edit
                //enable add user
                removeUserButton.setEnabled(false);
                editUserButton.setEnabled(false);

            }
            else {
            //Single selection: permit all operations.
                removeUserButton.setEnabled(true);
                editUserButton.setEnabled(true);
            }
      }

    }

}